﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;

namespace Classes
{
    [DataContract]
    public class Connection
    {

        IList<Flight> flights;
        IList<City> cities;
        City departureCity;
        City destinationCity;
        int totalTime;
        int totalPrice;
        int numberOfFlightChange;
        int noOfseatsLeft;
        int noOfSeatsReservedByCustomer;
        DateTime departureTime;
        DateTime arrivalTime;
        string currency;
        int id;


        public Connection() // the same as flight with fields in constructor
        {
            flights = new List<Flight>();
            cities = new List<City>();

        }




        public int NoOfSeatsReservedByCustomer1
        {
            get { return noOfSeatsReservedByCustomer; }
            set { noOfSeatsReservedByCustomer = value; }
        }

        public string Currency
        {
            get { return currency; }
            set { currency = value; }
        }

        [DataMember]
        public DateTime ArrivalTime
        {
            get { return arrivalTime; }
            set { arrivalTime = value; }
        }

        [DataMember]
        public DateTime DepartureTime
        {
            get { return departureTime; }
            set { departureTime = value; }
        }

        public int NoOfSeatsReservedByCustomer
        {
            get { return NoOfSeatsReservedByCustomer1; }
            set { NoOfSeatsReservedByCustomer1 = value; }
        }

        public int NoOfseatsLeft
        {
            get { return noOfseatsLeft; }
            set { noOfseatsLeft = value; }
        }

        [DataMember]
        public int NumberOfFlightChange
        {
            get { return numberOfFlightChange; }
            set { numberOfFlightChange = value; }
        }
        [DataMember]
        public int TotalPrice
        {
            get { return totalPrice; }
            set { totalPrice = value; }
        }


        public int TotalTime
        {
            get { return totalTime; }
            set { totalTime = value; }
        }

        [DataMember]
        public City DestinationCity
        {
            get { return destinationCity; }
            set { destinationCity = value; }
        }

        [DataMember]
        public City DepartureCity
        {
            get { return departureCity; }
            set { departureCity = value; }
        }

        public IList<City> Cities
        {
            get { return cities; }
            set { cities = value; }
        }

        [DataMember]
        public IList<Flight> Flights
        {
            get { return flights; }
            set { flights = value; }
        }

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        public IList<Flight> FlightList()
        {
            return Flights;
        }

        public void SetCityList(IList<City> visited)
        {
            Cities = visited;
        }

        public void SetFlightList(IList<Flight> value)
        {
            Flights = value;
        }

        public void RemoveFlight(Flight flight)
        {
            Flights.Remove(flight);
        }

        public void AddFlight(Flight flight)
        {
            Flights.Add(flight);
        }

        public IList<Flight> MakeFlightsOfCitiesForDijkstra(IList<City> list)
        {
            for (int i = 0; i < list.Count() - 1; i++)
            {
                City c = list[i];
                City x = list[i + 1];
                List<Flight> flightsOfCity = c.Flights().FindAll(z => z.To == x);
                Flight y = flightsOfCity.First(z => z.DepartureTime >= c.LastHour);
                Flights.Add(y);
            }
            SetFlightList(Flights);
            return Flights;
        }
        public IList<Flight> MakeFlightsOfCities(IList<City> list)
        {
            DateTime old = DateTime.Now;
            for (int i = 0; i < list.Count() - 1; i++)
            {
                City c = list[i];
                City x = list[i + 1];
                List<Flight> flightsOfCity = c.Flights().FindAll(z => z.To == x);
                Flight y = flightsOfCity.First(d => d.Used == false);
               
                    Flights.Add(y);
               
                
            }
            SetFlightList(Flights);

            return Flights;
        }

        public IList<City> CitiesList()
        {
            return Cities;
        }

    }
}
